package com.gdcn.zb.sys.service.impl;

import java.util.List;

import com.gdcn.zb.base.BaseService;
import com.gdcn.zb.base.exception.DaoException;
import com.gdcn.zb.base.exception.ServiceException;
import com.gdcn.zb.sys.dao.IRoleDao;
import com.gdcn.zb.sys.service.IRoleService;
import com.gdcn.zb.sys.valueobject.Role;

public class RoleServiceImpl extends BaseService implements IRoleService {
	private IRoleDao roleDao ; 
	
	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public void createRole(Role role) throws ServiceException {
		try{
			roleDao.createRole(role);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
	}

	public void deleteRole(String id) throws ServiceException {
		try{
			roleDao.deleteRole(id);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
	}

	public Role findRoleById(String id) throws ServiceException {
		Role role = null;
		try{
			role = roleDao.findRoleById(id);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		return role;
	}

	public List<Role> findRoleByRoleName(String roleName)throws ServiceException {
		// TODO Auto-generated method stub
		return null;
	}

	public void updateRole(Role role)throws ServiceException {
		try{
			roleDao.updateRole(role);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
	}

	public List<Role> listRoleOfAll() {
		List<Role> list = null;
		try{
			list = roleDao.listRoleOfAll();
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		return list;
	}

	public void deleteRole(String[] id) throws ServiceException {
		if(id != null){
			for(int i=0;i<id.length;i++){
				deleteRole(id[i]);
			}
		}
		
	}

}